# $Id: PKGBUILD 92521 2013-06-07 16:21:25Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Tino Reichardt <milky-archlinux@mcmilk.de>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - patches for hardfloat and ensure our cflags are used

pkgname=dietlibc
pkgver=0.33
pkgrel=4
pkgdesc="a libc optimized for small size"
arch=('i686' 'x86_64')
url="http://www.fefe.de/dietlibc/"
license=("GPL")
options=('staticlibs')
#source=(http://www.kernel.org/pub/linux/libs/dietlibc/$pkgname-$pkgver.tar.bz2)
source=("http://www.fefe.de/dietlibc/dietlibc-$pkgver.tar.bz2"
        '0020-fixes-for-ARMv7.diff'
        '0027-fix-arm-mmap.diff'
        '0036-fix-jmp_buf-size-on-armhf.diff')
md5sums=('9d541b9a6623b04ec12e5248b82db7c0'
         '5be4af2e186bce29c379854c9ad79551'
         '49d6be0a081e426ddf35ec1f67268930'
         'f9006823cf707723482811ceea0c1ed4')

build() {
  cd $srcdir/$pkgname-$pkgver

  # patches for hardfloat
  if [ "$CARCH" == 'armv7h' -o "$CARCH" == 'armv6h' ]; then
    sed -i 's/3-6/3-7/' Makefile
    perl -pi -e 's/\r\n/\n/g' arm/md5asm.S
    patch -p1 -i ../0020-fixes-for-ARMv7.diff
    patch -p1 -i ../0027-fix-arm-mmap.diff
    patch -p1 -i ../0036-fix-jmp_buf-size-on-armhf.diff
  fi
  
  # ensure our cflags are used
  sed -i "s/CFLAGS=-pipe/CFLAGS=$CFLAGS/" Makefile

  make
}

package() {
  cd $srcdir/$pkgname-$pkgver
  make DESTDIR=$pkgdir install
  mkdir -p $pkgdir/usr/bin
  ln -s /opt/diet/bin/diet $pkgdir/usr/bin/diet
}
